from datetime import timedelta

from celery import shared_task
from django.utils import timezone
from django_celery_results.models import TaskResult


@shared_task
def cleanup_dcr():
    """
    清空三十日前的定时任务执行记录
    """
    now = timezone.now()
    # days30_ago = now - timedelta(days=30)
    days30_ago = now - timedelta(days=1)
    result = TaskResult.objects.filter(periodic_task_name__isnull=True, date_done__lte=days30_ago).delete()
    return result
